package com.summer.Thread;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

class NewThread implements Callable {
    @Override
    public Object call() throws Exception {
        int sum = 0;
        for (int i = 1; i <= 100 ; i++) {
            if (i%2==0){
                System.out.println(i);
                sum+=i;
            }
        }
        return sum;
    }
}
public class CallableTest{
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        NewThread newThread = new NewThread();
        FutureTask futureTask = new FutureTask(newThread);
        new Thread(futureTask).start();
        Object sum = futureTask.get();
        System.out.println("总和为:"+sum);

    }
}
